<?php
/*
 * fun:随堂测试，老师开启了随堂测试的前提下，便可做随堂测试
 * 老师关闭了，只可以看错题分析
 * time : 2016-3-8
 * author : lijj
 */
session('openId','testlijj');
class ClassTestAction extends Action {
	public function index(){
		$TEAQUIZ = D('Teacher/TeacherQuiz');
		$openId = session('?openId')? : $this->error('由于某种原因，您的某些关键数据丢失，请在微信端发送000000重新授权登录,然后再获取该链接');
        $STUDENT = D('Student/StudentInfo');
        $class = $STUDENT->where('openId="'.$openId.'"')->getField('class');
        $quizInfo = D('Teacher/TeacherQuizState')->where('class="'.$class.'班"')->select();
        $this->assign('quizInfo',$quizInfo)->display();
	}

	//做随堂测试
	public function classTest(){
		/*========定义一些变量======*/
		$openId = session('?openId')? : $this->error('由于某种原因，您的某些关键数据丢失，请在微信端发送000000重新授权登录,然后再获取该链接');
		$QUIZ = D('Teacher/TeacherQuizQuestionbank');
		$TESTREC = D('Student/StudentClasstestRecord');
		$quizName = "第一章";
		$quizNum = $QUIZ->where('quizName = "'.$quizName.'"')->count();
		/*=========使用分页函数将题目分配在页面中=======*/
		import('@.ORG.Page');// 导入分页类
		$count      = $quizNum;
        $testItem = new Page($count,1);    //每一页放5条数据 
        $testItem->setConfig('header','题');
       

        $list=$QUIZ->limit($testItem->firstRow.','.$testItem->listRows)->order('id')->select();
        // $list=$QUIZ->select();
        $page=$testItem->show();   
        $this->assign ("page", $page );   
        $this->assign ("list", $list );   
        // p($list);
        $this->display();

		/*=========分配到html页面中=======*/
	}

	//取得正确答案
	public function getRightAns(){
		/*=========判断是否通过ajax方式传输数据=======*/
		if(IS_AJAX){
			/*=========定义变量=======*/
            $itemid   = I('post.itemid');
            $openid   = I('post.openid');
            $answer   = I('post.answer');
            $enterTime = I('enterTime');
            $leaveTime = time();
			$QUESTION = M('questionbank');
			$RECORD = M('random_answer_record');
			
			/*=======获取正确答案=======*/	
			$ajaxreturn['rightAnswer']     = $QUESTION->where("id={$itemid}")->getField("rightAnswer");
			$ajaxreturn['analysisPicPath'] = $QUESTION->where("id={$itemid}")->getField("analysisPicPath");
			$ajaxreturn['analysisPicName'] = $QUESTION->where("id={$itemid}")->getField("analysisPicName");
			
			/*=======记录答题情况=====*/
			$this->recordOption($answer,$openid,$itemid,$enterTime,$leaveTime,$ajaxreturn['rightAnswer']);
		
			
			/*====返回答案解析到前台==*/
			$this->ajaxReturn($ajaxreturn);     
        }
		else 
			$this->ajaxReturn('非法的请求方式'); 
	}

}
	
